Q1(4 marks)

Accept a sequence of comma separated integers as input and assign each of those numbers the sum of their digits. Store those key-value pairs in a dictionary. Use dict comprehension. Output should be exactly as shown below.

Also remember that your code should be readable, go through past notebooks for more clarification (that is, indent the one liner comprehension into a more readable block). One mark will be deducted if your code is not readable.

Of course, learn to Google what you don't know. Note that input is exactly as shown. There should be only one input(.....) in your code.

Example:

Input:

12,34,45,56,67,78,89

Output:

12 ~ 3
34 ~ 7
45 ~ 9
56 ~ 11
67 ~ 13
78 ~ 15
89 ~ 17

Input:

0, 94, 123, 654353

Output:

0 ~ 0
94 ~ 13
123 ~ 6
654353 ~ 26

Q2(6 marks)

Write a program to print the following pattern for a given number of lines. List comprehension should be used for creating the new list of lists/tuples and then double for-loop should be used for printing the pattern.

In other words do not use the expensive append() operation

Example:

Input: 5

Output:

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Input: 7

Output:

1
2 8
3 9 14
4 10 15 19
5 11 16 20 23
6 12 17 21 24 26
7 13 18 22 25 27 28